package com.logos.servlet.rep;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 响应字符数据：设置字符数据的响应体
 */
@WebServlet("/resp1")
public class ResponseTest01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取字符输出流
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
//        resp.setHeader("content-type","text/html");
        // 输出数据
        writer.write("你好");
        writer.write("<h1>hello, response</h1>");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
